package wang.lxl.remoteexecute;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Properties;

/**
 * @Author lixilin
 * @Date 2021/4/24 9:55
 * @Description 为Javaclass劫持Java.lang.system提供支持
 * 除了 out 和 err 外,其余的都直接转发给system处理
 */
public class HackSystem {
    public final static InputStream in = System.in;
    private static ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    public final static PrintStream out = new PrintStream(buffer);
    public final static PrintStream err = out;
    public static String getBufferString() {
        return buffer.toString();
    }
    public static void clearBuffer() {
        buffer.reset();
    }
    public static void setSecurityManager(final SecurityManager s){
        System.setSecurityManager(s);
    }

    public static SecurityManager getSecurityManager(){
       return System.getSecurityManager();
    }

    public static long currentTimeMillis() {
        System.out.println("自定义system类执行了....");
        return System.currentTimeMillis();
    }

    public static void arrayCopy(Object src, int srcPos, Object dest, int destPos, int length) {
        System.arraycopy(src,srcPos,dest,destPos,length);
    }

    public static int identityHashCode(Object x) {
        return System.identityHashCode(x);
    }
    public static  long nanoTime(){
        return System.nanoTime();
    }
    public static Properties getProperties() {
        return System.getProperties();
    }
}
